<?php
if(!class_exists('Memcache'))
{
	class Memcache{}
	define("NO_MEM_ENABLED", true);
}
class MM
{
	private $memcachedIsEnabled = false;
	private $memcacheObj = null;
	private $servers = array();
	private function __construct($servers)
	{
		if(class_exists('Memcache') && !defined('NO_MEM_ENABLED'))
		{
			$this->memcachedIsEnabled = true;
			$this->servers = $servers;
			$this->initServer();
		}
	}

	public static function getObj($servers = array())
	{
		static $obj = null;
		if($obj == null)
		{
			$obj = new MM($servers);
		}
		return $obj;
	}

	private function initServer()
	{
		$this->memcacheObj = new Memcache();
		foreach($this->servers as $server)
		{
			$timeOut = isset($server['timeout']) ? intval($server['timeout']) : 1;
			$this->memcacheObj->addServer($server['host'], $server['port'], $timeOut);
		}
	}

	public function isUseCache()
	{
		return $this->memcachedIsEnabled;
	}
	
	public function set($k, $v)
	{
		$this->memcacheObj->set($k, $v);
	}
	
	public function get($k)
	{
		return $this->memcacheObj->get($k);
	}
}